package sort.select;

import java.util.Arrays;

/**
 * @author justnow
 * Created on 2020-09-30
 * Description
 */
public class SelectSort {
    public static void sort(int[] nums) {
        
        int length = nums.length;

        for (int i = 0; i < length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < length; j++) {
                if (nums[minIndex] > nums[j]) {
                    minIndex = j;
                }
            }
            if (minIndex != i) {
                int temp = nums[minIndex];
                nums[minIndex] = nums[i];
                nums[i] = temp;
            }
        }
    }

    public static void main(String[] args) {
        int[] nums = {7, 2, 10, 19, 17, 25, 1, 8};
        sort(nums);
        System.out.println(Arrays.toString(nums));
    }
}
